	{include file="Public:header" /}
	<!-- 载入公共头部文件-->
	<link href="__PUBLIC__/Home/css/reg.css" type="text/css" rel="stylesheet" >
	<div id="regBox">
		<div class='header'>
			已有本站账号?<a href="__MODULE__/Login/index">登录</a>
		</div>
		<div class='form'>
		<form action="__URL__/regUser" method="post" id="regForm">
			<dl class='focus'>
				<dt>邮箱</dt>
				<dd class='text'><input class='must' type="text" ajax=1  name="email" /></dd>
				<dd class='prompt'>用于登录和找回密码，不会公开</dd>
			</dl>
			<dl>
				<dt>用户名</dt>
				<dd class='text'><input class='must' type="text" ajax=1 name="username"/></dd>
				<dd class='prompt'></dd>
			</dl>
			<dl>
				<dt>创建密码</dt>
				<dd class='text'><input class='must' id="password" type="password" name="password" /></dd>
				<dd class='prompt'></dd>
			</dl>
			<dl>
				<dt>确认密码</dt>
				<dd class='text'><input class='must' type="password" name="password_d"/></dd>
				<dd class='prompt'></dd>
			</dl>
			<!-- <dl>
				<dt>所在城市</dt>
				<dd class='area'>
					<select id="s_province" name="s_province"></select>
					<select id="s_city" name="s_city" ></select>
					<select id="s_county" name="s_county"></select>
					<script type="text/javascript" src="__ROOT__/classLibs/area/area.js"></script>
					<script type="text/javascript">_init_area();</script>
				</dd>
				<dd class='prompt'></dd>
			</dl> -->
			<dl>
				<dt>验证码</dt>
				<dd class='text code' style="width:200px;height:auto;"><input class='must' type="text" ajax=1 name="code"/> <img id="codeImg" src="__URL__/showCode" style="height:30px;"></dd>
				<dd class='prompt'></dd>
			</dl>
			<dl>
				<dt></dt>
				<dd class='submit'><input type="submit" value="注册"></dd>
			</dl>
		</form>
		</div>
	</div>
</body>
<script>
$(function(){
	$("#codeImg").click(function(){
		var src = '__URL__/showCode/mt/'+Math.random();
		$(this).attr('src', src);
	});
});
//验证码点击切换
/* function changeCode(obj){
	var src = '__URL__/showCode/mt/'+Math.random();
	$(obj).attr('src', src);
} */

$(function(){
	 check()
	 $("#regForm").submit(function(){
	 });
});
var checkForm = {
		'email': {
			focus : '请填写你的邮箱',
			empty : '邮箱不能为空',
			preg  : /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,
			error : '邮箱格式错误'
		},
		'username': {
			focus : '请填写你的用户名',
			empty : '用户名不能为空',
			preg  : /^[a-z]\w{5,15}$/i,
			error : '用户名格式错误'
		},
		'password': {
			focus : '请填写你的密码',
			empty : '密码不能为空',
			preg  : /^\S{6,32}$/,
			error : '密码格式错误'
		},
		'password_d': {
			focus : '确认密码',
			empty : '确认密码不能为空',
			error : '密码不一致'
		},
		'code': {
			focus : '请输入验证码',
			empty : '验证码不能为空',
			preg  : /^[a-z0-9]{4}$/i,
			error : '验证码格式错误'
		}
	};
function check(){
	var aElsArr = $("#regForm .must");
	aElsArr.each(function(){
		$(this).focus(function(){
			var name = $(this).attr('name');
			var msg = checkForm[name]['focus'];
			showFocus($(this), msg);
			$(this).blur(function(){
				var val = $(this).val();
				//值为空的情况
				if(val == ''){
					var msg = checkForm[name]['empty'];
					showErrot($(this), msg);
					return false;
				}
				//确认密码不需要验证
				if(name == 'password_d'){
					if($("input[name='password']").val() != val){
						var msg = checkForm[name]['error'];
						showErrot($(this), msg);
						return false;
					}
				}else{
				//验证正则
					var preg = checkForm[name]['preg'];
					if(!preg.test(val)){
						var msg = checkForm[name]['error'];
						showErrot($(this), msg);
						return false;
					}
				}
				//需要ajax校验
				if($(this).attr('ajax') == 1){
					var self = $(this);
					$.ajax({
						url : '__URL__/check',
						type : 'post',
						data : name+'='+val,
						dataType : 'json',
						success : function(result){
							if(result.status === true){
								showSuccess(self, '');
							}else{
								if(name == 'code'){
									var src = '__URL__/showCode/mt/'+Math.random();
									$("#codeImg").attr('src', src);
								} 
								showErrot(self, result.message);
							}
								
						}
					});
				//输入正确
				}else{
					showSuccess($(this), '');
				}
			});
		});
	});
}

/**
 * 显示获得焦点提示
 */
function showFocus(obj, msg){
	getThis(obj, msg, 'focus');
}
/**
 * 显示错误提示
 */
function showErrot(obj, msg){
	getThis(obj, msg, 'error');
}
/**
 * 显示成功提示
 */
function showSuccess(obj, msg){
	getThis(obj, msg, 'success');
}
/**
 * 获取元素位置
 */
function getThis(obj, msg, status){
	var parent = $(obj).parents('dl');
	var oPrompt = parent.find('.prompt');
	parent.attr('class', status);
	oPrompt.text(msg);
}

//alert(checkForm['email']['empty']);
$("#regForm").submit(function(){
	var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
});
</script>
</html>